package com.itheima.case2.dao;

import com.itheima.case2.pojo.vo.AddUser;
import com.itheima.case2.pojo.vo.QueryPageBean;
import com.itheima.case2.pojo.po.Role;
import com.itheima.case2.pojo.po.User;
import com.itheima.case2.pojo.vo.UpdateUser;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

public interface UserDao {

    Long findTotalCount(QueryPageBean queryPageBean);

    List<User> findListByPage(QueryPageBean queryPageBean);

    //对应的sql在UserDao.xml文件中
    Integer addUser(AddUser user);

    void addUserRoles(@Param("uid") Integer uid, @Param("roleIds") List<String> roleIds);

    @Update("update t_user set username=#{username},email=#{email},password=#{password} where id=#{id}")
    Integer updateUser(UpdateUser user);

    @Delete("delete from t_user where id = #{id}")
    Integer deleteUserById(Integer id);

    @Select("select tr.* from t_user tu, t_role tr, t_user_role tur " +
            "where tu.id = tur.user_id and tr.id = tur.role_id " +
            "and tu.id = #{id}")
    Set<Role> findRoleByUserId(String id);


    @Delete("delete from t_user_role where user_id = #{id}")
    void deleteRoleById(Integer id);
}
